/* SPU相关的接口请求函数 */

import request from '@/utils/request';

import type {
  SpuListParamsModel,
  SpuPageListModel,
  BaseSaleAttrListModel,
  SpuModel,
  SpuImageListModel,
  SpuSaleAttrListModel,
} from './model/spuModel';

// 定义请求地址的枚举
enum Api {
  GetSpuList = '/admin/product',
  GetBaseSaleAttrList = '/admin/product/baseSaleAttrList',
  SaveSpu = '/admin/product/saveSpuInfo',
  UpdateSpu = '/admin/product/updateSpuInfo',
  GetSpuSaleAttrList = '/admin/product/spuSaleAttrList',
  GetSpuImageList = '/admin/product/spuImageList',
  GetSpuInfo = '/admin/product/getSpuById',
}


//   获取Spu分页列表
//   @param categoryIds 三级分类id对象
//   @returns SpuPageListModel SPU分页列表
export const getSpuListApi = ({page,limit,category3Id}:SpuListParamsModel)=>{
    return request.get<any,SpuPageListModel>(Api.GetSpuList + `/${page}/${limit}`, {
        params: { // 指定query参数
          category3Id,
        },
      });
}


 
//  获取基础销售属性列表
//  @returns BaseSaleAttrListModel
  export const getBaseSaleAttrListApi = () => {
    return request.get<any, BaseSaleAttrListModel>(Api.GetBaseSaleAttrList);
  };
  

  /*
   * 添加或更新SPU
   * @param spu spu对象
   */
  export const addOrUpdateSpuApi = (spu: SpuModel) => {
    return request.post(spu.id ? Api.UpdateSpu : Api.SaveSpu, spu);
  };
  


  /*
   * 获取图片列表
   * @param spuId
   * @returns SpuImageListModel  SPU图片列表
   */
  export const getSpuImageListApi = (spuId: number) => {
    return request.get<any, SpuImageListModel>(Api.GetSpuImageList + `/${spuId}`);
  };
  

  /*
   * 获取销售属性列表
   * @param spuId
   * @returns SpuSaleAttrListModel  Spu销售属性值列表
   */
  export const getSpuSaleAttrListApi = (spuId: number) => {
    return request.get<any, SpuSaleAttrListModel>(Api.GetSpuSaleAttrList + `/${spuId}`);
  };
  


  /*
   * 获取SPU详情
   * @param spuId
   * @returns SpuModel  spu详情信息
   */
  export const getSpuInfoApi = (spuId: number) => {
    return request.get<any, SpuModel>(Api.GetSpuInfo + `/${spuId}`);
  };

